

package ro.ase.catalog.security.filter;

import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.security.intercept.method.AbstractMethodDefinitionSource;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public class DefaultMethodDefinitionSource extends
        AbstractMethodDefinitionSource {

    private AspectJMethodMatcher methodMatcher;
    private LinkedHashMap<String, ConfigAttributeDefinition> methodMap = new LinkedHashMap<String, ConfigAttributeDefinition>();

    public DefaultMethodDefinitionSource(AspectJMethodMatcher methodMatcher,
            LinkedHashMap<String, ConfigAttributeDefinition> methodMap) {
        this.methodMatcher = methodMatcher;
        this.methodMap = methodMap;
    }

    @SuppressWarnings("unchecked")
    public Collection getConfigAttributeDefinitions() {
        return null;
    }

    @Override
    protected ConfigAttributeDefinition lookupAttributes(Method method) {
        Set<Entry<String, ConfigAttributeDefinition>> set = getMethodMap()
                .entrySet();
        for (Entry<String, ConfigAttributeDefinition> entry : set) {
            String pattern = entry.getKey();
            boolean matched = getMethodMatcher().match(pattern, method);
            if (matched) {
                return entry.getValue();
            }
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public ConfigAttributeDefinition getAttributes(Method method,
            Class targetClass) {
        return null;
    }

    public Map<String, ConfigAttributeDefinition> getMethodMap() {
        return methodMap;
    }

    public AspectJMethodMatcher getMethodMatcher() {
        return methodMatcher;
    }
}
